home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / pcw.zip / MSINT29A.ASM < prev    next >
Assembly Source File  |  1991-12-21  |  6KB  |  131 lines

  1.               Page      ,132
  2. ;****************************************************************
  3. ;* File Id.                       INT29A.ASM                    *
  4. ;* Author.                        Stan Milam.                   *
  5. ;* Date Written.                  11/05/89.                     *
  6. ;*                                                              *
  7. ;*              (c) Copyright 1991 by Stan Milam                *
  8. ;*                                                              *
  9. ;* Research material:                                           *
  10. ;*      PC Tech Journal, April 1987, Exception Handling         *
  11. ;*      Advanced MS-DOS, Second Edition, by Ray Duncan          *
  12. ;*      MS-DOS Encyclopedia                                     *
  13. ;****************************************************************
  14. ;
  15.               Dosseg                        ;Declare Normal Segmentation
  16. IFDEF POWERC
  17.               .Model    Large               ;Large Model for Power C
  18. ELSE
  19.               .Model    Large,C             ;And Turbo, MSC & Zortech
  20. ENDIF
  21.               Extrn     _psp:Word           ;Segment Address of PSP
  22.               Extrn     old_int29:dword
  23.               .Code
  24.               Extrn     Int29c:Far
  25. ;
  26. ; Declare storage in the code segment to save ES & DS
  27. ;
  28. int29_es      Dw        0
  29. int29_ds      Dw        0
  30. save_ss       Dw        ?
  31. save_sp       Dw        ?
  32.               Page
  33. ;
  34. ;****************************************************************
  35. ;*                             Int29                            *
  36. ;*                                                              *
  37. ;* This routine will be entered when interrupt 29 is generated  *
  38. ;* by DOS.                                                      *
  39. ;*                                                              *
  40. ;* Major Goals: Save stack, Restore application DS & ES, push   *
  41. ;* information on stack & call C routine, return to DOS with    *
  42. ;* return information in AX                                     *
  43. ;* If -1 (0xffff) is returned by C routine then restore regs &  *
  44. ;* invoke the original INT 24 handler.                          *
  45. ;****************************************************************
  46. ;
  47.               Public    Int29
  48. Int29         Proc      Far
  49.               Push      Bp                  ;Set up the stack frame
  50.               Mov       Bp,Sp
  51.               Push      Ds                  ;Preserve the registers
  52.               Push      Es
  53.               Push      Di
  54.               Push      Si
  55.               Push      Ax
  56.               Push      Bx
  57.               Push      Cx
  58.               Push      Dx
  59. IFDEF POWERC
  60.               Push      Cs:[int29_ds]       ;Restore Data Segment
  61.               Pop       Ds
  62. ELSE
  63.               Mov       Bx,@Data            ;This the way we restore DS &
  64.               Mov       Ds,Bx               ;get the PSP address in Turbo C
  65. ENDIF
  66.               Mov       Bx,Seg _psp         ;and Microsoft C.
  67.               Mov       Es,Bx               ;This method accomodates all of
  68.               Mov       Bx,Es:[_psp]        ;the different memory models.
  69.               Mov       Es,Bx
  70. ;
  71. ;The following code saves the stack registers in the code segment, and
  72. ;restores the stack registers to the values found in the PSP of the program
  73. ;which was their value when the DOS interrupt occured.  This way we can use
  74. ;our stack without fear of blowing DOS out of the water.
  75. ;
  76.               Mov       Cs:[save_ss],Ss     ;Save Stack address in Code Seg
  77.               Mov       Cs:[save_sp],Sp     ;So we can switch
  78.               Mov       Ss,Es:[30h]         ;Switch stacks, this allows
  79.               Mov       Sp,Es:[2eh]         ;Child process to use interrupt
  80.               Sti                           ;Start the interrupts
  81. ;
  82. ;These next push is a the character to print.
  83. ;It is passed to the C function.
  84. ;
  85.               Push      Ax
  86.               Call      Int29c
  87.               Pop       Bx                  ;Remove parm in Bx
  88.               Mov       ss,cs:[save_ss]     ;Switch stack back
  89.               Mov       sp,cs:[save_sp]
  90.               Cmp       Ax,1                ;Check for good return
  91.               Je        GoodExit            ;If good return get out.
  92.               Mov       Ax,Bx               ;Else....
  93.               Mov       Bx,Seg old_int29    ;  Setup to call original int 29
  94.               Mov       Es,Bx
  95.               Pushf                         ;Push flags to fake an interrupt
  96.               Call      Es:Dword Ptr [old_int29]
  97. GoodExit:
  98.               Pop       Dx                  ;Restore registers
  99.               Pop       Cx
  100.               Pop       Bx
  101.               Pop       Ax
  102.               Pop       Si
  103.               Pop       Di
  104.               Pop       Es
  105.               Pop       Ds
  106.               Pop       Bp
  107.               Iret
  108. Int29         Endp
  109. IFDEF POWERC
  110.               Page
  111. ;
  112. ;********************************************************************
  113. ;*                           _Save_ES_DS_                           *
  114. ;*                                                                  *
  115. ;* Here we save Es & Ds values in the Code Segment so we can re-    *
  116. ;* trieve and restore them when the interrupt occurs.  If we do not *
  117. ;* reset these registers our C code will not work.  This routine is *
  118. ;* called by the installation routine set_int29().                  *
  119. ;********************************************************************
  120. ;
  121.               Public    Save_Int29_Regs
  122. Save_Int29_Regs  Proc      Far
  123.               Push      Es                  ;Save Es on Stack
  124.               Pop       Cs:[int29_es]       ;Pop it into our Code Segment
  125.               Push      Ds                  ;Same thing with Ds
  126.               Pop       Cs:[int29_ds]
  127.               Ret
  128. Save_Int29_Regs  Endp
  129. ENDIF
  130.               End
  131.